package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.Teacher;
import net.sf.json.JSONArray;

/**
 * Servlet implementation class TChangeCla
 */
@WebServlet("/TChangeCla")
public class TChangeCla extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TChangeCla() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//doGet(request, response);
		response.setContentType("text/json;charset=utf-8");
		String cla_id = request.getParameter("cla_id");
		String c_id = request.getParameter("c_id");
		String year = request.getParameter("year");
		String tea_id = (String)request.getSession().getAttribute("tea_id");
		Teacher tea = new Teacher();
		
		try {
			tea = tea.ChangeData(tea_id, cla_id, c_id , year);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//System.out.println(tea.getStudent().get(0));
		int size=tea.getStudent().size();
		//System.out.println(size);
		JSONArray jsons=new JSONArray();
		//System.out.println(size);
		for(int i = 0 ; i<size ;i++)
		{
			jsons.add(tea.getStudent().get(i));
		}
		//System.out.println(jsons.toString());
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out=response.getWriter();
		out.println(jsons.toString());
		out.flush();
		out.close();


		
	}
	}

